import req from "./config"
import { Api } from "./config/Api"
import { IBannerItem, IPageInfo, IPromiseShell, ISingerDetailItem, ISongItem, ISongWithPage } from "./type"
import qs from "qs"
// 获取全部列表
export const getSongList = (): IPromiseShell<ISongItem[]> => req.get(Api.songList)
// 分页查询
export const getSongListByPage = (page?: IPageInfo, style?: string): IPromiseShell<ISongWithPage<ISongItem[]>> => req.get(`${Api.pageSongList}?${qs.stringify(page)} ${style ? '&style=' + style : ''}`)

//获取轮播图
export const getBanner = (): IPromiseShell<IBannerItem[]> => req.get(Api.bannerList)


// 根据歌单id获取歌单
export const getSongSheet = (id: number): IPromiseShell<ISingerDetailItem[]> => req.get(Api.getSongListById + id)


export interface ICommentItem {
  id: number;
  userId: number;
  songId?: any;
  songListId: number;
  content: string;
  createTime: number;
  type: number;
  up: number;
}
// 获取歌曲的评论
export const getSongComment = (id: number): IPromiseShell<ICommentItem[]> => req.get(Api.songComment + id)
// 获取歌单评论
export const getSongSheetComment = (id: number): IPromiseShell<ICommentItem[]> => req.get(Api.songSheetComment + id)

// 搜索 歌曲
export const getSearchSongDetail = (word: string): IPromiseShell<ISingerDetailItem[]> => req.get(Api.searchSongDetail + word)
// 搜索 歌单
export const getSearchSongSheet = (word: string): IPromiseShell<ISongItem[]> => req.get(Api.searchSongSheet + word)


//保存评论
export const saveComment = (comment: ICommentItem) => req.post(Api.saveComment, comment)

// 更新评论点赞
export const likeCommet = (id: number, num: number) => req.patch(`${Api.likeComment}/${id}/${num}`)